﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace NetCoreEFMySqlApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly DataContext Con;

        public UserController(DataContext context)
        {
            this.Con = context;
        }

        // POST api/User/{json}
        // 改
        [HttpPost]
        public IEnumerable<User> Post(User User)
        {
            Con.Update(User);

            var count = Con.SaveChanges();

            return Con.User;
        }

        // GET api/User/{id}
        // 删
        [HttpGet("{id}")]
        public IEnumerable<User> Get(int id)
        {
            User User = new User();
            User.ID = id;
            Con.Remove(User);

            var count = Con.SaveChanges();

            return Con.User;
        }
    }
}